<!DOCTYPE html>
<html>
<head>
  <title></title>
</head>
<body>
  <script>
    function convert(obj) {
      Object.keys(obj).forEach(key => {
        let value = obj[key];
        Object.defineProperty(obj, key, {
          get() {
            console.log(`getting key "${key}": ${value}`);
            return value;
          },
          set(newValue) {
            console.log(`setting key "${key}" to ${newValue}`)
            value = newValue;
          }
        });
      });
    }
    const obj = { foo: 123 };
    convert(obj);
    obj.foo;
    obj.foo = 234;
    obj.foo;
  </script>
</body>
</html>
